package com.yanqu.road.server.cmd.activity.xingyoushanshui.cross;

import com.yanqu.road.entity.activity.youxing.config.XingYouConfig;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.shanshui.XingYouShanShuiMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_HELP_AUTO_REWARD_FROM_CROSS,desc = "协助奖励补发(跨服返回)")
public class ShanShuiHelpRewardSendFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        XingYouConfig config = XingYouShanShuiMgr.getConfig();
        if(config == null){
            return;
        }

        XingYouShanShuiProto.ShanShuiHelpRewardSendMsg msg = XingYouShanShuiProto.ShanShuiHelpRewardSendMsg.parseFrom(yanQuMessage.getBytes());

        UserInfo userInfoInRAM = UserMgr.getUserInfoInRAM(msg.getUserId());
        if(userInfoInRAM == null){
            return;
        }

        String language = userInfoInRAM.getLanguage();
        String activityName = ServerLanguageMgr.getContent(config.getActivityInfo().getActivityName(), language);
        String mailTitle = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.AUTO_SEND_ACTIVITY_CROSS_RANK_REWARD_TITLE, language), activityName);
        String mailContent = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.AUTO_SEND_ACTIVITY_CROSS_RANK_REWARD_CONTENT, language), activityName);
        MailManager.sendMail(msg.getUserId(), eMailType.MARKETING.getValue(), msg.getReward(), mailContent, mailTitle);
    }
}
